<template>
    <div>
			<el-tabs v-model="active" type="border-card" style="margin-bottom:20px">
				<el-tab-pane label="脚本统计" name="1">
					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type4"
								:title="'脚本数量'"
								:num="String(case_count)"
								:sub="'个'"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>

						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type4"
								:title="'新增脚本数量'"
								:num="String(new_case_count)"
								:sub="'个'"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>

						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type4"
								:title="'回退问题检出个数'"
								:num="String(issue)"
								:sub="'个'"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>
					</el-row>
				</el-tab-pane>

				<el-tab-pane label="自动化测试" name="2">
					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type4"
								:title="'cts'"
								:num="String(passLabel.cts.count)"
								:sub="'次'"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>

						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type4"
								:title="'endurance'"
								:num="String(passLabel.endurance.count)"
								:sub="'次'"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>

						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type4"
								:title="'function'"
								:num="String(passLabel.function.count)"
								:sub="'次'"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>

						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type4"
								:title="'it'"
								:num="String(passLabel.it.count)"
								:sub="'次'"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>
					</el-row>

					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type4"
								:title="'monkey'"
								:num="String(passLabel.monkey.count)"
								:sub="'次'"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>

						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type4"
								:title="'mtbf'"
								:num="String(passLabel.mtbf.count)"
								:sub="'次'"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>

						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type4"
								:title="'performance'"
								:num="String(passLabel.performance.count)"
								:sub="'次'"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>

						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type4"
								:title="'stress'"
								:num="String(passLabel.stress.count)"
								:sub="'次'"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>
					</el-row>

					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type4"
								:title="'ut'"
								:num="String(passLabel.ut.count)"
								:sub="'次'"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>

						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type4"
								:title="'web'"
								:num="String(passLabel.web.count)"
								:sub="'次'"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>						
					</el-row>
				</el-tab-pane>
				<el-tab-pane label="自动化测试通过率" name="3">
					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type5"
								:title="'cts'"
								:num="formatter_rate(passLabel.cts.pass_rate)"
								:sub="'%'"
								:to_sub="common.type3"
								:cls="common.success"
							></info_label>
						</el-col>

						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type5"
								:title="'endurance'"
								:num="formatter_rate(passLabel.endurance.pass_rate)"
								:sub="'%'"
								:to_sub="common.type3"
								:cls="common.success"
							></info_label>
						</el-col>

						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type5"
								:title="'function'"
								:num="formatter_rate(passLabel.function.pass_rate)"
								:sub="'%'"
								:to_sub="common.type3"
								:cls="common.success"
							></info_label>
						</el-col>

						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type5"
								:title="'it'"
								:num="formatter_rate(passLabel.it.pass_rate)"
								:sub="'%'"
								:to_sub="common.type3"
								:cls="common.success"
							></info_label>
						</el-col>
					</el-row>

					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type5"
								:title="'monkey'"
								:num="formatter_rate(passLabel.monkey.pass_rate)"
								:sub="'%'"
								:to_sub="common.type3"
								:cls="common.success"
							></info_label>
						</el-col>

						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type5"
								:title="'mtbf'"
								:num="formatter_rate(passLabel.mtbf.pass_rate)"
								:sub="'%'"
								:to_sub="common.type3"
								:cls="common.success"
							></info_label>
						</el-col>

						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type5"
								:title="'performance'"
								:num="formatter_rate(passLabel.performance.pass_rate)"
								:sub="'%'"
								:to_sub="common.type3"
								:cls="common.success"
							></info_label>
						</el-col>

						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type5"
								:title="'stress'"
								:num="formatter_rate(passLabel.stress.pass_rate)"
								:sub="'%'"
								:to_sub="common.type3"
								:cls="common.success"
							></info_label>
						</el-col>
					</el-row>

					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type5"
								:title="'ut'"
								:num="formatter_rate(passLabel.ut.pass_rate)"
								:sub="'%'"
								:to_sub="common.type3"
								:cls="common.success"
							></info_label>
						</el-col>

						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type5"
								:title="'web'"
								:num="formatter_rate(passLabel.web.pass_rate)"
								:sub="'%'"
								:to_sub="common.type3"
								:cls="common.success"
							></info_label>
						</el-col>						
					</el-row>
				</el-tab-pane>
			</el-tabs>

			<el-tabs type="border-card" style="margin-bottom:20px">
				<el-tab-pane label="Total">
					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type"
								:title="common.titles[19]"
								:num="String(labelsData.test_count)"
								:sub="common.subs[0]"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.avg"
								:title="common.titles[37]"
								:num="formatter_rate(labelsData.av_pass_rate)"
								:sub="common.percent"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.avg"
								:title="'测试执行率'"
								:num="formatter_rate(labelsData.av_exec_rate)"
								:sub="common.percent"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>
					</el-row>
				</el-tab-pane>
				<el-tab-pane label="Verify-build">
					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type"
								:title="common.titles[19]"
								:num="String(labelsData.verify_test_count)"
								:sub="common.subs[0]"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.avg"
								:title="common.titles[33]"
								:num="formatSeconds(labelsData.verify_avg_test_time)"
								:sub="common.subs[1]"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.avg"
								title="等待时长"
								:num="formatSeconds(labelsData.verify_avg_wait_time)"
								:sub="common.subs[1]"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label_compare
								:params="generate_label_params(formatter_rate(labelsData.verify_passrate), [true, 99], 'percent', common.titles[37], common.avg)"
								:sub="common.percent"
								:to_sub="common.to_sub + ' (目标=100%)'"
							></info_label_compare>
						</el-col>
					</el-row>
				</el-tab-pane>
				<el-tab-pane label="Daily-build">
					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type"
								:title="common.titles[19]"
								:num="String(labelsData.daily_test_count)"
								:sub="common.subs[0]"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.avg"
								:title="common.titles[33]"
								:num="formatSeconds(labelsData.daily_avg_test_time)"
								:sub="common.subs[1]"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.avg"
								title="等待时长"
								:num="formatSeconds(labelsData.daily_avg_wait_time)"
								:sub="common.subs[1]"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label_compare
								:params="generate_label_params(formatter_rate(labelsData.daily_passrate), [true, 90], 'percent', common.titles[37], common.avg)"
								:sub="common.percent"
								:to_sub="common.to_sub + ' (目标>=90%)'"
							></info_label_compare>
						</el-col>
					</el-row>
				</el-tab-pane>
				<el-tab-pane label="Release-build">
					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type"
								:title="common.titles[19]"
								:num="String(labelsData.release_test_count)"
								:sub="common.subs[0]"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.avg"
								:title="common.titles[33]"
								:num="formatSeconds(labelsData.release_avg_test_time)"
								:sub="common.subs[1]"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.avg"
								title="等待时长"
								:num="formatSeconds(labelsData.release_avg_wait_time)"
								:sub="common.subs[1]"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label_compare
								:params="generate_label_params(formatter_rate(labelsData.release_passrate), [true, 80], 'percent', common.titles[37], common.avg)"
								:sub="common.percent"
								:to_sub="common.to_sub + ' (目标>=80%)'"
							></info_label_compare>
						</el-col>
					</el-row>
				</el-tab-pane>
			</el-tabs>
			<el-card class="box-card m-b" shadow="never" style="margin-bottom:20px">
				<div slot="header" class="clearfix">
					<span>自动化测试趋势</span>
				</div>
				<div>
					<ve-line
						:data="autoData"
						:settings="autoChartSettings"
						:data-empty="dataEmpty"
						:data-zoom="dataZoom"
					></ve-line>
				</div>
			</el-card>

			<el-card class="box-card m-b" style="margin-bottom: 20px;" shadow="never">
			<div slot="header" class="clearfix">
				<span>云平台使用情况</span>
			</div>
			<div>
				<VTable	
					:isShow="false"
					:border="true"												
					:tablesize="userSize"
					:tablecurrent="userCurrent"
					:tabletotal="userTotal"
					:table-data="userTable"
					:table-label="userObj"
					@handleSortChange="handleSortChange"
					@tableSizeChange="userSizeChange"
					@tableCurrentImportDeptChange="userCurrentChange"
				>
				</VTable>
			</div>
		</el-card>

			<el-card class="box-card m-b" shadow="never">
							<div slot="header" class="clearfix">
					<span>日统计汇总</span>
				</div>
				<div>
					<el-table
						:data="currentData"
						border
						style="width: 100%; margin-bottom: 20px"
						@sort-change="sortChange">
						<el-table-column prop="update_date" label="日期" :sortable="'custom'"></el-table-column>
						<el-table-column prop="test_count" label="总测试" sortable></el-table-column>
						<el-table-column prop="daily_test_count" label="Daily测试"></el-table-column>
						<el-table-column prop="verify_test_count" label="Verify测试"></el-table-column>
						<el-table-column prop="release_test_count" label="Release测试"></el-table-column>
						<el-table-column prop="av_pass_rate" label="平均通过率"></el-table-column>
						<el-table-column prop="av_exec_rate" label="平均执行率"></el-table-column>
						<el-table-column label="详情" width="120px">
							<template slot-scope="scope">
								<el-button
									type="primary"
									plain
									@click="viewDetail(scope.$index, scope.row)"
									size="medium"
								>查看详情</el-button>
							</template>
						</el-table-column>
					</el-table>
					<el-pagination
						@size-change="handleSizeChange"
						@current-change="handleCurrentChange"
						:current-page="currentPage"
						:page-sizes="[10, 15, 50, 100]"
						:page-size="currentSize"
						layout="total, sizes, prev, pager, next, jumper"
						:total="totalCount"
					></el-pagination>
				</div>
			</el-card>
    </div>
</template>

<script>
import { pagingData } from './utils.js';
import common from '@/components/devops/get_data';
import info_label from '@/components/devops/info_label.vue';
import autotest_result from '@/components/devops/autotest_result.vue';
import info_label_compare from '@/components/devops/info_label_compare.vue';
import { getHeader } from '@/app.config';
import VTable from '@/components/charts/table'
import 'v-charts/lib/style.css';
import 'echarts/lib/component/dataZoom';
export default {
    components: {
        info_label,
        info_label_compare,
        autotest_result,
				VTable
    },
    props: {
        params: Object
    },
    data () {
        this.dataZoom = [{
			type: 'slider',
			start: 0,
			end: 100
	    }];
        return {
            labelsArr: ['平均通过率', '平均执行率', '平均覆盖率'],
			y_keys7: ['av_pass_rate', 'av_exec_rate', 'av_cover'],
			totalCount: 0,
			currentPage: 1,
			currentSize: 10,
			userTable: [],
			userObj: [
				{
					label: '人员',
					param: 'username',
					align: 'center'
				},
				{
					label: '登录次数',
					param: 'login_count',
					align: 'center',
					sortable: true,
					render: (row) => {
						return `${row.login_count}次`
					}
				},
				{
					label: '脚本上传',
					param: 'script_upload_count',
					align: 'center',
					sortable: true,
					render: (row) => {
						return `${row.script_upload_count}次`
					}
				},
				{
					label: '脚本上传个数',
					param: 'case_count',
					align: 'center',
					sortable: true,
					render: (row) => {
						return `${row.case_count}个`
					}
				},
				{
					label: '脚本更新',
					param: 'script_update_count',
					align: 'center',
					sortable: true,
					render: (row) => {
						return `${row.script_update_count}次`
					}
				},
				{
					label: '脚本删除',
					param: 'script_delete_count',
					align: 'center',
					sortable: true,
					render: (row) => {
						return `${row.script_delete_count}次`
					}
				},
				{
					label: '设备注册',
					param: 'device_register_count',
					align: 'center',
					sortable: true,
					render: (row) => {
						return `${row.device_register_count}次`
					}
				},
				{
					label: '创建任务',
					param: 'create_task_count',
					align: 'center',
					sortable: true,
					render: (row) => {
						return `${row.create_task_count}次`
					}
				}
			],
			userSize: 10,
			userCurrent: 1,
			userTotal: 0,
			dataEmpty: true,
			labelsData: {},
			common,
			active: '1',
			case_count: 0,
			new_case_count: 0,
			issue: 0,
			passLabel: {},
			table_auto_data: [],
			currentData: [],
			autoChartSettings: {
				yAxisType: ['percent'],
				labelMap: {
					av_pass_rate: '平均通过率',
					av_exec_rate: '平均执行率'
				}
			},
			autoData: {
				columns: ['update_date', 'av_pass_rate', 'av_exec_rate'],
				rows: []
			},
        }
    },
    methods: {
		init_datas: function(projectId, dates) {
			this.get_data_by_url(projectId, dates);
			this.get_table_data(projectId, dates);
			this.getNewCase(projectId, dates)
			this.getIssue(projectId, dates)
			this.getResults(projectId, dates)
			this.getNewTable(projectId, dates)
		},
		getFix(data) {
				if (null == data || "undefined" == typeof(data) || "" == data) {
						return 0;
				} else {
						return data
				}
		},
		formatter_rate(value) {
				let str
				if(value) {
					str = Number(value*100).toFixed(2)
				} else {
					str = '0.00'
				}
				return str
		},
		handleSortChange(val) {
			let key = val['prop']
			let compare1 = function(obj1, obj2) {
				let val1 = obj1[key]
				let val2 = obj2[key]
				if (val1 < val2) {
					return -1
				} else if (val1 > val2) {
					return 1
				} else {
					return 0
				}
			}
			let compare2 = function(obj1, obj2) {
				let val1 = obj1[key]
				let val2 = obj2[key]
				if (val1 < val2) {
					return 1
				} else if (val1 > val2) {
					return -1
				} else {
					return 0
				}
			}
			if (val['order'] === 'ascending') {
				this.userTable = this.userTable.sort(compare1)
			} else if (val['order'] === 'descending') {
				this.userTable = this.userTable.sort(compare2)
			} else {
				key = 'login_count'
				this.userTable = this.userTable.sort(compare2)
			}
		},
		fomatFloat(src, pos) {
			return Math.round(src * Math.pow(10, pos)) / Math.pow(10, pos);
		},
		generate_label_params: function(val1, val2, dataType, dataTitle, label) {
			if (typeof val1 === 'undefined') {
				val1 = 0;
			}
			var labelParam;
			if (dataType === 'time') {
				var standardTime = val2[1] * 60;
				if (val1) {
					if (val2[0]) {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.formatSeconds(val1),
							status: val1 > standardTime ? 'reach' : 'down',
							difference:
								val1 > standardTime
									? ''
									: this.formatSeconds(standardTime - val1)
						};
					} else {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.formatSeconds(val1),
							status: val1 > standardTime ? 'up' : 'reach',
							difference:
								val1 > standardTime
									? this.formatSeconds(val1 - standardTime)
									: ''
						};
					}
				} else {
					labelParam = {
						type: label,
						title: dataTitle,
						num: this.formatSeconds(val1),
						status: 'reach',
						difference: ''
					};
				}
				return labelParam;
			} else if (dataType === 'percent') {
				if (val1) {
					if (val2[0]) {
						labelParam = {
							type: label,
							title: dataTitle,
							status: val1 > val2[1] ? 'reach' : 'down',
							difference:
								val1 > val2[1] ? '' : this.fomatFloat(val2[1] - val1, 2) + '%',
							num: this.fomatFloat(val1, 2)
						};
					} else {
						labelParam = {
							type: label,
							title: dataTitle,
							status: val1 > val2[1] ? 'up' : 'reach',
							difference:
								val1 > val2[1] ? this.fomatFloat(val1 - val2[1], 2) + '%' : '',
							num: this.fomatFloat(val1, 2)
						};
					}
				} else {
					labelParam = {
						type: label,
						title: dataTitle,
						status: 'reach',
						difference: '',
						num: this.fomatFloat(val1, 2)
					};
				}
				return labelParam;
			} else if (dataType === 'frequency') {
				if (val1) {
					if (val2[0]) {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.fomatFloat(val1, 2),
							status: val1 > val2[1] ? 'reach' : 'down',
							difference:
								val1 > val2[1] ? '' : this.fomatFloat(val2[1] - val1, 2)
						};
					} else {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.fomatFloat(val1, 2),
							status: val1 > val2[1] ? 'up' : 'reach',
							difference:
								val1 > val2[1] ? this.fomatFloat(val1 - val2[1], 2) : ''
						};
					}
				} else {
					labelParam = {
						type: label,
						title: dataTitle,
						num: this.fomatFloat(val1, 2),
						status: 'reach',
						difference: ''
					};
				}
				return labelParam;
			} else if (dataType === 'multiple') {
				if (val1) {
					if (val2[0]) {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.fomatFloat(val1, 2),
							status: val1 > val2[1] ? 'reach' : 'down',
							difference:
								val1 > val2[1] ? '' : this.fomatFloat(val2[1] - val1, 2)
						};
					} else {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.fomatFloat(val1, 2),
							status: val1 > val2[1] ? 'up' : 'reach',
							difference:
								val1 > val2[1] ? this.fomatFloat(val1 - val2[1], 2) : ''
						};
					}
				} else {
					labelParam = {
						type: label,
						title: dataTitle,
						num: this.fomatFloat(val1, 2),
						status: 'reach',
						difference: ''
					};
				}
				return labelParam;
			} else {
				labelParam = {
					type: label,
					title: dataTitle,
					num: this.fomatFloat(val1, 2),
					status: 'reach',
					difference: ''
				};
				return labelParam;
			}
		},
		formatSeconds(value) {
			if (isNaN(value)) {
				value = 0;
			}
			var theTime = parseInt(value); // 秒
			var theTime1 = 0; // 分
			var theTime2 = 0; // 小时
			var theTime3 = 0; // 天
			if (theTime > 60) {
				theTime1 = parseInt(theTime / 60);
				theTime = parseInt(theTime % 60);
				if (theTime1 > 60) {
					theTime2 = parseInt(theTime1 / 60);
					theTime1 = parseInt(theTime1 % 60);
					if (theTime2 > 24) {
						theTime3 = parseInt(theTime2 / 24);
						theTime2 = parseInt(theTime2 % 24);
					}
				}
			}
			var result = '' + parseInt(theTime) + '秒';
			if (theTime1 > 0) {
				result = '' + parseInt(theTime1) + '分' + result;
			}
			if (theTime2 > 0) {
				result = '' + parseInt(theTime2) + '时' + result;
			}
			if (theTime3 > 0) {
				result = '' + parseInt(theTime3) + '天' + result;
			}
			return result;
		},
		filterObject: function() {
			console.log('111')
		},
		viewDetail(index, row) {
			let routeData = this.$router.resolve({
				path:
					'/project/details/' +
					this.params.projectId + '/' +
					this.params.projectName +
					'_@_' +
					row.update_date +
					'_@_autotest'
			});
			window.open(routeData.href, '_blank');
		},
		update_ui: function() {
			setTimeout(this.$refs.autotest_pie.draw, 100);
			this.first = false;
		},
		sortChange: function(val) {
			var key = val['prop'];
			var compare1 = function(obj1, obj2) {
				var val1 = obj1[key];
				var val2 = obj2[key];
				if (val1 < val2) {
					return -1;
				} else if (val1 > val2) {
					return 1;
				} else {
					return 0;
				}
			};
			var compare2 = function(obj1, obj2) {
				var val1 = obj1[key];
				var val2 = obj2[key];
				if (val1 < val2) {
					return 1;
				} else if (val1 > val2) {
					return -1;
				} else {
					return 0;
				}
			};
			var arr = this.table_auto_data;
			if (val['order'] === 'ascending') {
                this.currentData = pagingData(arr.sort(compare1), this.totalCount, this.currentPage, this.currentSize)
			} else if (val['order'] === 'descending') {
                this.currentData = pagingData(arr.sort(compare2), this.totalCount, this.currentPage, this.currentSize)
			} else {
				key = 'update_date';
                this.currentData = pagingData(arr.sort(compare2), this.totalCount, this.currentPage, this.currentSize)
			}
		},
		handleSizeChange: function(size) {
			this.currentSize = size;
            this.currentData = pagingData(this.table_auto_data, this.totalCount, this.currentPage, this.currentSize)
		},
		handleCurrentChange: function(page) {
			this.currentPage = page;
            this.currentData = pagingData(this.table_auto_data, this.totalCount, this.currentPage, this.currentSize)
		},
		userCurrentChange(val) {
			this.userCurrent = val
		},
		userSizeChange(val) {
			this.userSize = val
		},
		getNewTable(projectId, dates) {			
			this.$axios.get(process.env.VUE_APP_KANBAN_HOST +
                '/api/devops/automate/project/behavior?projectId=' +
                projectId + '&date=' + dates,
				{headers: getHeader()})
				.then(res => {
					if (res.status == 200) {
						if (res.data.code === 200) {
							this.userTable = res.data.date
							if(this.userTable && this.userTable.length) {
								this.userTotal = this.userTable.length
							}
						}
					}
				}).catch(error => {
					console.log(error)
				})
		},
		getNewCase(projectId, dates) {			
			this.$axios.get(process.env.VUE_APP_KANBAN_HOST +
                '/api/devops/automate/project/case?projectId=' +
                projectId + '&date=' + dates,
				{headers: getHeader()})
				.then(res => {
					if (res.status == 200) {
						if (res.data.code === 200) {
							this.case_count = res.data.case_count
							this.new_case_count = res.data.new_case_count
						}
					}
				}).catch(error => {
					console.log(error)
				})
		},
		getIssue(projectId, dates) {	
			this.$axios.get(process.env.VUE_APP_KANBAN_HOST +
                '/api/devops/automate/project/issue?projectId=' +
                projectId + '&date=' + dates,
				{headers: getHeader()})
				.then(res => {
					if (res.status == 200) {
						if (res.data.code === 200) {
							this.issue = res.data.reg_count						
						}
					}
				}).catch(error => {
					console.log(error)
				})
		},
		getResults(projectId, dates) {
			this.$axios.get(process.env.VUE_APP_KANBAN_HOST +
                '/api/devops/automate/project/result?projectId=' +
                projectId + '&date=' + dates,
				{headers: getHeader()})
				.then(res => {
					if (res.status == 200) {
						if (res.data.code === 200) {
							this.passLabel = res.data.data
						}
					}
				}).catch(error => {
					console.log(error)
				})
		},
		get_table_data: function(projectId, dates) {
			this.table_auto_data = [];
			this.currentData = [];
			this.autoData.rows = [];
			this.dataEmpty = true;
			var self = this;
			this.$axios.get(
                process.env.VUE_APP_KANBAN_HOST +
                '/api/devops/automate/table_summary?projectId=' +
                projectId + '&date=' + dates, {headers: getHeader()})
				.then(function(response) {
					if (response.status == 200) {
						if (response.data.code === 200) {
							var data = response.data.data;
							for (var i = 0; i < data.length; i++) {
								var tableDict = {
									update_date: data[i]['update_date'],
									test_count: data[i]['test_count'] + '次',
									daily_test_count: data[i]['daily_test_count'] + '次',
									verify_test_count: data[i]['verify_test_count'] + '次',
									release_test_count: data[i]['release_test_count'] + '次',
									av_pass_rate: self.formatter_rate(data[i]['av_pass_rate']) + '%',
									av_exec_rate: self.formatter_rate(data[i]['av_exec_rate']) + '%'
								};
								self.table_auto_data.push(tableDict);
							}
							self.autoData.rows = data.reverse();
							self.dataEmpty = false;
							self.totalCount = self.table_auto_data.length;
							self.currentPage = 1;
							self.currentSize = 10;
							if (self.totalCount === 0) {
								self.currentData = [];
								self.dataEmpty = true;
							} else {
                                self.currentData = pagingData(self.table_auto_data, self.totalCount, self.currentPage, self.currentSize)
							}
						}
					}
				});
		},
		get_data_by_url: function(projectId, dates) {
			var self = this;
			self.labelsData = {}
			this.$axios.get(
				process.env.VUE_APP_KANBAN_HOST +
				'/api/devops/automate/project/summary?projectId=' +
				projectId + '&date=' + dates, {headers: getHeader()})
				.then(function(response) {
					if (response.status == 200) {
						if (response.data.code === 200) {
							var data = response.data.data;
							self.labelsData = data;
						}
					}
				})
				.catch(function(err) {
					console.log(err);
			});
		},
    },
    watch: {
        params: {
			handler: function(val) {
                const projectId = val.projectId === 'undefined' ? '' : val.projectId;
                const dates = val.time === 'undefined' ? '' : val.time;
				this.init_datas(projectId, dates);
			},
			deep: true
		}
    },
    mounted() {
			const projectId = this.params.projectId === 'undefined' ? '' : this.params.projectId;
			const dates = this.params.time === 'undefined' ? '' : this.params.time;
			this.init_datas(projectId, dates);
		}
}
</script>
